import SessionUserUtil from '../../data/session/sessionUser'
import SessionUtil, {JxbHttpClient} from "../../data/session/session"
import LangUtil from '../../utils/lang';


Page({
  /**
   * 页面的初始数据
   */
  data: {
    point: 0,
	icon_list:[],
    rules: [],
    level: 0,
    ids: '',
    user: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    SessionUtil.getInstance().then(()=>{
      return Promise.all([(new JxbHttpClient()).request('AppMaster/Index/getMemberInfo'), SessionUserUtil.getInstance()])
    }).then(value => {
      let [jxbResp, sessionUser] = value
      let { account_lv, member_msg, icon_list,member_info_item_ids, this_month_get_point} = jxbResp.data
      let lang = {
        shopping_points : LangUtil.translate('shopping_points'),
        shopping_points_unit : LangUtil.translate('shopping_points_unit'),
      }
      this.setData({
        lang,
        point: this_month_get_point,
		    icon_list:icon_list,
        rules: member_msg,
        level: account_lv,
        ids: member_info_item_ids,
        user: {
          avatarUrl: sessionUser.avatarUrl,
          realName: sessionUser.realName,
          mobile: sessionUser.phoneNumber
        }
      })
    })
  },
  buy() {
    const { ids } = this.data
    wx.navigateTo({
      url: '/pages/productList/index/index?ids=' + ids + '&tag=会员商品',
    })
  },
  
  /**
   * 我的收益
   */
  linkGain(){
	  wx.navigateTo({
	    url: '/subPage/member/gain',
	  })
  },
  
  /**
   * 我的邀请
   */
  linkInvite(){
	  wx.navigateTo({
	    url: '/subPage/member/invite',
	  })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    getApp().getSaleMode()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})